const articleModel = require('../moudle/article');

const getArticleList = async (req, res) => {
  try {
    const { title = '', status = '', page = 1, pageSize = 10 } = req.query;
    // 参数校验
    const pageNum = Math.max(Number(page) || 1, 1);
    const sizeNum = Math.max(Number(pageSize) || 10, 1);
    const result = await articleModel.getArticleList({ title, status, page: pageNum, pageSize: sizeNum });
    res.json({ code: 200, data: result });
  } catch (err) {
    res.status(500).json({ code: 500, msg: '服务器错误', error: err.message });
  }
};

module.exports = {
  getArticleList
}; 